import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Iterator;

import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.query.ResultSetFormatter;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Statement;



public class TestQuery {
	public String readQuery(String targetFile) throws IOException {

		BufferedReader reader = new BufferedReader(new FileReader(targetFile));
		int readNumber = 0;
		char[] tA = new char[1024];
		StringBuffer queryBuffer = new StringBuffer(1000);
		String qString;

		try {

			while ((readNumber = reader.read(tA)) != -1) {

				qString = String.valueOf(tA, 0, readNumber);
				queryBuffer.append(qString);
				tA = new char[1024];
			}

			reader.close();

		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		// System.out.println(queryBuffer.toString());
		return queryBuffer.toString();

	}

	public void runQuery(String queryString, Model model) {

		Query query = QueryFactory.create(queryString);
		// System.out.println(query.toString()) ;
		QueryExecution qe = QueryExecutionFactory.create(query, model);
		ResultSet results = qe.execSelect();
		Model temp = ModelFactory.createDefaultModel();
		
//        while(results.hasNext() ) {
//            QuerySolution sol = results.next();
//            sol.
//        }
		
	
		ResultSetFormatter.out(System.out, results, query);
		qe.close();
	}

}
